package com.sen.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sen.entity.DruginfoEntity;
import com.sen.entity.SupplierEntity;
import com.sen.service.SupplierService;
import com.sen.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 供应商表
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2021-01-08 17:54:40
 */
@RestController
@RequestMapping("supplier")
public class SupplierController {
    @Autowired
    private SupplierService supplierService;

    /**
     * 查询所有厂家查询使用
     * @return
     */
    @GetMapping("/allSupplier")
    public R allSupplier(){

        List<SupplierEntity> supplierList = supplierService.list();

        return R.ok().put("supplierList",supplierList);
    }

    /**
     * 查询所有厂家展示使用
     * @param supplier 分页使用
     * @return
     */
    @GetMapping("/queryAll")
    public R queryAll(@RequestParam Map<String,String> supplier){
        QueryWrapper<SupplierEntity> wrapper = new QueryWrapper<>();
        Page<SupplierEntity> page = new Page<>(Integer.parseInt(supplier.get("current")),Integer.parseInt(supplier.get("size")));
        Page<SupplierEntity> supplierList = supplierService.page(page, wrapper);
        return R.ok().put("supplierList",supplierList);
    }

    /**
     * 增加或修改生产商
     * @param supplierEntity supplier实体类
     */
    @PostMapping("/supplierAddOrUpd")
    public void supplierAddOrUpd(SupplierEntity supplierEntity) {
        supplierService.saveOrUpdate(supplierEntity);
    }
}
